
package com.admissions.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.admissions.R;
import com.admissions.model.ItemInfo;
import com.admissions.model.MonThi;

public class MonThiAdapter extends BaseAdapter {

    private ArrayList<MonThi> mItems;

    private LayoutInflater mInflater;

    public MonThiAdapter(Context context, ArrayList<MonThi> items) {
        this.mItems = items;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_layout, parent, false);
        }

        ImageView itemIcon = (ImageView) convertView.findViewById(R.id.item_icon);
        TextView itemName = (TextView) convertView.findViewById(R.id.item_name);
        TextView itemCaption = (TextView) convertView.findViewById(R.id.item_description);

        ItemInfo itemInfo = mItems.get(position);
        convertView.setTag(itemInfo);

        itemIcon.setImageBitmap(itemInfo.icon);
        itemName.setText(itemInfo.name);
        itemCaption.setText(itemInfo.description);

        return convertView;
    }

}
